package com.hsmpay.mobile.service.user.impl;

import com.hsmpay.common.pojo.qian4.Qian4SendLog;
import com.hsmpay.common.service.impl.BaseServiceSupport;
import com.hsmpay.common.util.DateConvertUtil;
import com.hsmpay.common.util.OrderTypeUtil;
import com.hsmpay.mobile.dao.trans.TransOrderDao;
import com.hsmpay.mobile.dao.user.UserTransLimitDao;
import com.hsmpay.mobile.pojo.trans.TransOrder;
import com.hsmpay.mobile.pojo.user.UserTransLimit;
import com.hsmpay.mobile.service.trans.Qian4SendLogService;
import com.hsmpay.mobile.service.user.UserTransLimitService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 用户交易限制 服务接口实现类 userMoneyService
 * @author lyc
 * 建立时间：2015-4-24
 */
@Service("userTransLimitService")
public class UserTransLimitServiceImpl extends BaseServiceSupport<UserTransLimit, Long> implements UserTransLimitService<UserTransLimit, Long> {

    @Resource(name = "userTransLimitDao")
    private UserTransLimitDao<UserTransLimit, Long> userTransLimitDao;

    //交易订单Dao
    @Resource(name = "transOrderDao")
    private TransOrderDao<TransOrder, Long> transOrderDao;
    @Resource(name = "qian4SendLogService")
    protected Qian4SendLogService<Qian4SendLog, Long> qian4SendLogService;
    /**
     * 余额充值、卡卡转账、信用卡还款等校验
     */
    public Map<String, Object> transCheck(Long userId, Long roleId, String bankCard, Double money, Long orderTypeId, String functionKey, Integer channelId) throws Exception {
        try {
            Map<String, Object> userLimitMap = new HashMap<String, Object>();
            userLimitMap = getUserLeastLimit(userId, functionKey);


            Map<String, Object> map = new HashMap<String, Object>();
            if (channelId != null && "RECEIVABLES".equals(functionKey) && channelId == 34) {//瑞晟并且是收款
                userLimitMap.put("dayMaxAmt", 50000);
                userLimitMap.put("fdDayMaxAmt", 50000);
            }
            //判断单笔金额（单笔最大、单笔最小）
            map = transMoneyLimit(userLimitMap, roleId, money);
            if (map != null) return map;


            //判断单日总金额（单日最大、单日单卡最大）
            map = totalMoneyLimit(userId, orderTypeId, bankCard, money, userLimitMap, roleId);
            if (map != null) return map;


            //判断笔数（单日笔数、单日单卡笔数）
            map = numberLimit(userId, orderTypeId, bankCard, userLimitMap, roleId);
            if (map != null) return map;


            return map;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }


    /**
     * 查询用户限制总笔数
     */
    public Long getUserLimitNumber(Map<String, Object> userLimitMap, Long roleId, String bankCard) throws Exception {

        if (bankCard != null) {
            return Long.parseLong(userLimitMap.get("dayCardCnt").toString());//单日单卡笔数限制
        }
        if (roleId == 2) {
            return Long.parseLong(userLimitMap.get("dayCnt").toString());//单日交易笔数限制
        } else {
            return Long.parseLong(userLimitMap.get("fdDayCnt").toString());//单日封顶笔数限制
        }

    }

    /**
     * 查询用户限制总金额
     */
    public Double getUserLimitMoney(Map<String, Object> userLimitMap, Long roleId, String bankCard) throws Exception {


        if (bankCard != null) {
            return Double.parseDouble(userLimitMap.get("dayCardAllAmt").toString());//单日单卡金额限制
        }
        if (roleId == 2) {
            return Double.parseDouble(userLimitMap.get("dayAllAmt").toString());//单日交易金额限制
        } else {
            return Double.parseDouble(userLimitMap.get("fdDayAllAmt").toString());//单日封顶金额限制
        }

    }


    /**
     * 查询用户最低限制
     */
    public Map<String, Object> getUserLeastLimit(Long userId, String functionKey) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();

        UserTransLimit userTransLimit = new UserTransLimit();
        userTransLimit.setUserId(userId);
        userTransLimit.setFunctionKey(functionKey);
        userTransLimit.setLimitType(3);//特殊限制
        userTransLimit = userTransLimitDao.searchEntity(userTransLimit);

        if (userTransLimit != null) {//如果存在特殊限制
            map.put("dayMinAmt", userTransLimit.getDayMinAmt());
            map.put("dayMaxAmt", userTransLimit.getDayMaxAmt());
            map.put("dayCardAllAmt", userTransLimit.getDayCardAllAmt());
            map.put("dayAllAmt", userTransLimit.getDayAllAmt());
            map.put("dayCardCnt", userTransLimit.getDayCardCnt());
            map.put("dayCnt", userTransLimit.getDayCnt());

            map.put("fdDayAllAmt", userTransLimit.getFdDayAllAmt());
            map.put("fdDayCnt", userTransLimit.getFdDayCnt());
            map.put("fdDayMinAmt", userTransLimit.getFdDayMinAmt());
            map.put("fdDayMaxAmt", userTransLimit.getFdDayMaxAmt());

            map.put("dayMaxQueryCnt", userTransLimit.getDayMaxQueryCnt());
        } else {//不存在特殊限制
            UserTransLimit u = new UserTransLimit();
            u.setFunctionKey(functionKey);
            u.setLimitType(1);//默认限制
            u = userTransLimitDao.searchEntity(u);

            UserTransLimit utl = new UserTransLimit();
            utl.setUserId(userId);
            utl.setFunctionKey(functionKey);
            utl = userTransLimitDao.searchEntity(utl);

            if (utl == null) {//没有限制

                map.put("dayMinAmt", u.getDayMinAmt());
                map.put("dayMaxAmt", u.getDayMaxAmt());
                map.put("dayCardAllAmt", u.getDayCardAllAmt());
                map.put("dayAllAmt", u.getDayAllAmt());
                map.put("dayCardCnt", u.getDayCardCnt());
                map.put("dayCnt", u.getDayCnt());

                map.put("fdDayAllAmt", u.getFdDayAllAmt());
                map.put("fdDayCnt", u.getFdDayCnt());
                map.put("fdDayMinAmt", u.getFdDayMinAmt());
                map.put("fdDayMaxAmt", u.getFdDayMaxAmt());
                map.put("dayMaxQueryCnt", u.getDayMaxQueryCnt());

                //添加默认限制
                u.setId(null);
                u.setUserId(userId);
                u.setLimitType(2);//用户限制
                userTransLimitDao.insertEntity(u);

            } else {
                Double dayMinAmt = utl.getDayMinAmt() == 0 ? u.getDayMinAmt() : u.getDayMinAmt() == 0 ? utl.getDayMinAmt() :
                        utl.getDayMinAmt() < u.getDayMinAmt() ? utl.getDayMinAmt() : u.getDayMinAmt();
                Double dayMaxAmt = utl.getDayMaxAmt() == 0 ? u.getDayMaxAmt() : u.getDayMaxAmt() == 0 ? utl.getDayMaxAmt() :
                        utl.getDayMaxAmt() < u.getDayMaxAmt() ? utl.getDayMaxAmt() : u.getDayMaxAmt();
                Double dayCardAllAmt = utl.getDayCardAllAmt() == 0 ? u.getDayCardAllAmt() : u.getDayCardAllAmt() == 0 ? utl.getDayCardAllAmt() :
                        utl.getDayCardAllAmt() < u.getDayCardAllAmt() ? utl.getDayCardAllAmt() : u.getDayCardAllAmt();
                Double dayAllAmt = utl.getDayAllAmt() == 0 ? u.getDayAllAmt() : u.getDayAllAmt() == 0 ? utl.getDayAllAmt() :
                        utl.getDayAllAmt() < u.getDayAllAmt() ? utl.getDayAllAmt() : u.getDayAllAmt();
                Long dayCardCnt = utl.getDayCardCnt() == 0 ? u.getDayCardCnt() : u.getDayCardCnt() == 0 ? utl.getDayCardCnt() :
                        utl.getDayCardCnt() < u.getDayCardCnt() ? utl.getDayCardCnt() : u.getDayCardCnt();
                Long dayCnt = utl.getDayCnt() == 0 ? u.getDayCnt() : u.getDayCnt() == 0 ? utl.getDayCnt() :
                        utl.getDayCnt() < u.getDayCnt() ? utl.getDayCnt() : u.getDayCnt();
                Double fdDayAllAmt = utl.getFdDayAllAmt() == 0 ? u.getFdDayAllAmt() : u.getFdDayAllAmt() == 0 ? utl.getFdDayAllAmt() :
                        utl.getFdDayAllAmt() < u.getFdDayAllAmt() ? utl.getFdDayAllAmt() : u.getFdDayAllAmt();
                Long fdDayCnt = utl.getFdDayCnt() == 0 ? u.getFdDayCnt() : u.getFdDayCnt() == 0 ? utl.getFdDayCnt() :
                        utl.getFdDayCnt() < u.getFdDayCnt() ? utl.getFdDayCnt() : u.getFdDayCnt();
                Double fdDayMinAmt = utl.getFdDayMinAmt() == 0 ? u.getFdDayMinAmt() : u.getFdDayMinAmt() == 0 ? utl.getFdDayMinAmt() :
                        utl.getFdDayMinAmt() < u.getFdDayMinAmt() ? utl.getFdDayMinAmt() : u.getFdDayMinAmt();
                Double fdDayMaxAmt = utl.getFdDayMaxAmt() == 0 ? u.getFdDayMaxAmt() : u.getFdDayMaxAmt() == 0 ? utl.getFdDayMaxAmt() :
                        utl.getFdDayMaxAmt() < u.getFdDayMaxAmt() ? utl.getFdDayMaxAmt() : u.getFdDayMaxAmt();

                Long dayMaxQueryCnt = utl.getDayMaxQueryCnt() == 0 ? u.getDayMaxQueryCnt() : u.getDayMaxQueryCnt() == 0 ? utl.getDayMaxQueryCnt() :
                        utl.getDayMaxQueryCnt() < u.getDayMaxQueryCnt() ? utl.getDayMaxQueryCnt() : u.getDayMaxQueryCnt();

                map.put("dayMinAmt", dayMinAmt);
                map.put("dayMaxAmt", dayMaxAmt);
                map.put("dayCardAllAmt", dayCardAllAmt);
                map.put("dayAllAmt", dayAllAmt);
                map.put("dayCardCnt", dayCardCnt);
                map.put("dayCnt", dayCnt);

                map.put("fdDayAllAmt", fdDayAllAmt);
                map.put("fdDayCnt", fdDayCnt);
                map.put("fdDayMinAmt", fdDayMinAmt);
                map.put("fdDayMaxAmt", fdDayMaxAmt);
                map.put("dayMaxQueryCnt", dayMaxQueryCnt);

            }

        }


        return map;
    }



    /**
     * 查询单日交易笔数（单日总笔数、单日单卡总笔数）
     *
     * @param userId
     * @param orderTypeId 交易类型
     * @param bankCard    银行卡号（可为空）
     * @return
     * @throws Exception
     */
    public Map<String, Object> numberLimit(Long userId, Long orderTypeId, String bankCard, Map<String, Object> userLimitMap, Long roleId) throws Exception {
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            Date date = new Date();
            String day = DateConvertUtil.dateString(date);
            String yesterday = DateConvertUtil.dateString(DateConvertUtil.getSpecifiedDayBefore(date));


            TransOrder transOrder = new TransOrder();
            transOrder.setUserId(userId);
            transOrder.setStartDate(DateConvertUtil.stringDateTime(yesterday + " 23:00:00"));
            transOrder.setEndDate(DateConvertUtil.stringDateTime(day + " 23:00:00"));
            transOrder.setOrderTypeId(orderTypeId);//交易类型
            if (orderTypeId == 8L) {//如果是提现
                transOrder.setOtherParam(" (O.STATUS = 1 OR O.STATUS = 2) ");
            } else {
                transOrder.setStatus(1);//交易成功状态
            }
            transOrder.setBankCard(null);//银行卡号
            //查询今日成功交易次数
            int count = transOrderDao.getEntityCount(transOrder);

            //通过用户限制表查出用户限制笔数userId、roleId、functionKey、bankCard
            Long limitNumber = getUserLimitNumber(userLimitMap, roleId, null);

            //判断是否超限
            if (limitNumber != 0 && count >= limitNumber.intValue()) {
                map.put("flag", false);
                map.put("code", "fk0005");
                map.put("value", limitNumber);
                map.put("description", "支付失败-次数超限，单日支持最大次数为$param次!");
                return map;
            }

            transOrder.setBankCard(bankCard);//银行卡号
            //查询今日成功交易次数
            int cardCount = transOrderDao.getEntityCount(transOrder);

            //通过用户限制表查出用户限制笔数userId、roleId、functionKey、bankCard
            Long cardLimitNumber = getUserLimitNumber(userLimitMap, roleId, bankCard);

            //判断是否超限
            if (cardLimitNumber != 0 && cardCount >= cardLimitNumber.intValue()) {
                map.put("flag", false);
                map.put("code", "fk0006");
                map.put("value", cardLimitNumber);
                map.put("description", "支付失败-次数超限，单日单卡支持最大次数为$param次!");
                return map;
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * 查询单日交易总金额 （单日总金额、单日单卡总金额）
     *
     * @param userId
     * @param orderTypeId 交易类型
     * @param bankCard    银行卡号（可为空）
     * @param transMoney  交易金额
     * @return
     * @throws Exception
     */
    public Map<String, Object> totalMoneyLimit(Long userId, Long orderTypeId, String bankCard, double transMoney, Map<String, Object> userLimitMap, Long roleId) throws Exception {
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            Date date = new Date();
            String day = DateConvertUtil.dateString(date);
            String yesterday = DateConvertUtil.dateString(DateConvertUtil.getSpecifiedDayBefore(date));


            TransOrder transOrder = new TransOrder();
            transOrder.setUserId(userId);
            transOrder.setStartDate(DateConvertUtil.stringDateTime(yesterday + " 23:00:00"));
            transOrder.setEndDate(DateConvertUtil.stringDateTime(day + " 23:00:00"));
            transOrder.setOrderTypeId(orderTypeId);//交易类型
            if (orderTypeId == 8L) {//如果是提现
                transOrder.setOtherParam(" (O.STATUS = 1 OR O.STATUS = 2) ");
            } else {
                transOrder.setStatus(1);//交易成功状态
            }
            transOrder.setBankCard(null);//银行卡号
            //查询今日成功交易总金额
            double totalMoney = transOrderDao.getTransMoneySum(transOrder);//查询 用户 当天提现 成功和正在处理中的 提现总金额
            double tempTotalMoney = transMoney + totalMoney;

            //通过用户限制表查出用户限制笔数
            Double limitMoney = getUserLimitMoney(userLimitMap, roleId, null);

            //判断金额是否合格
            if (limitMoney != 0 && tempTotalMoney > limitMoney) {
                map.put("flag", false);
                map.put("code", "fk0003");
                map.put("value", limitMoney);
                map.put("description", "支付失败-金额超限，单日支持最大金额为$param元!");
                return map;
            }


            transOrder.setBankCard(bankCard);//银行卡号
            //查询今日成功交易总金额
            double cardTotalMoney = transOrderDao.getTransMoneySum(transOrder);//查询 用户 当天提现 成功和正在处理中的 提现总金额
            double cardTempTotalMoney = transMoney + cardTotalMoney;

            //通过用户限制表查出用户限制笔数
            Double cardLimitMoney = getUserLimitMoney(userLimitMap, roleId, bankCard);
            //判断金额是否合格
            if (cardLimitMoney != 0 && cardTempTotalMoney > cardLimitMoney) {
                map.put("flag", false);
                map.put("code", "fk0004");
                map.put("value", cardLimitMoney);
                map.put("description", "支付失败-金额超限，单日单卡支持最大金额为$param元!");
                return map;
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * 单日单笔金额限制 （单日单笔最高、单日单笔最高最低）
     * @param userLimitMap
     * @param roleId
     * @param money  交易金额
     * @return
     * @throws Exception
     */
    public Map<String, Object> transMoneyLimit(Map<String, Object> userLimitMap, Long roleId, Double money) throws Exception {
        try {
            Map<String, Object> map = new HashMap<String, Object>();

            //单笔最小
            Double transMinMoney = 0.0;
            if (roleId == 2) {
                transMinMoney = Double.parseDouble(userLimitMap.get("dayMinAmt").toString());//单日交易金额限制
            } else {
                transMinMoney = Double.parseDouble(userLimitMap.get("fdDayMinAmt").toString());//单日封顶金额限制
            }

            if (transMinMoney != 0 && money < transMinMoney) {
                map.put("flag", false);
                map.put("code", "fk0001");
                map.put("value", transMinMoney);
                map.put("description", "支付失败-金额超限，单笔支持最小金额为$param元!");
                return map;
            }

            //单笔最大
            Double transMaxMoney = 0.0;
            if (roleId == 2) {
                transMaxMoney = Double.parseDouble(userLimitMap.get("dayMaxAmt").toString());//单日交易金额限制
            } else {
                transMaxMoney = Double.parseDouble(userLimitMap.get("fdDayMaxAmt").toString());//单日封顶金额限制
            }

            if (transMaxMoney != 0 && money > transMaxMoney) {
                map.put("flag", false);
                map.put("code", "fk0002");
                map.put("value", transMaxMoney);
                map.put("description", "支付失败-金额超限，单笔支持最大金额为$param元!");
                return map;
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * 提现笔数限制
     *
     * @param userId
     * @param limitNum
     * @return
     * @throws Exception
     */
    public boolean cashMoneyNumberLimit(Long userId, int limitNum) throws Exception {
        TransOrder transOrder = new TransOrder();
        transOrder.setUserId(userId);
        transOrder.setCreateDate(new Date());
        transOrder.setOrderTypeId(OrderTypeUtil.CASH_MONEY);//提现
        //transOrder.setOtherParam(" O.STATUS ");//交易成功状态
        int flag = transOrderDao.getEntityCount(transOrder);

        if (limitNum != 0 && limitNum <= flag) {
            //触发限制
            return true;
        } else {
            return false;
        }
    }

    /**
     * 提现总金额限制
     *
     * @param userId            用户ID
     * @param transMoney        交易额
     * @param totalMaxCashMoney 提现最大金额
     * @return
     * @throws Exception
     */
    public boolean cashMoneyTotalMoneyLimit(Long userId, double transMoney, double totalMaxCashMoney) throws Exception {
        Date date = new Date();
        String dateStr = DateConvertUtil.dateString(date);
        Date startDate = DateConvertUtil.stringDate(dateStr);//今天 00:00:00
        Date endDate = DateConvertUtil.getSpecifiedDayAfter(startDate);//第二天 00:00:00

        TransOrder transOrder = new TransOrder();
        transOrder.setUserId(userId);
        transOrder.setOrderTypeId(OrderTypeUtil.CASH_MONEY);//提现
        transOrder.setStartDate(startDate);
        transOrder.setEndDate(endDate);
        transOrder.setOtherParam(" (O.STATUS = 1 OR O.STATUS = 2) ");

        double totalMoney = transOrderDao.getTransMoneySum(transOrder);//查询 用户 当天提现 成功和正在处理中的 提现总金额
        double tempTotalMoney = transMoney + totalMoney;
        if (totalMaxCashMoney < tempTotalMoney) {//如果 允许最大提现的金额 小于  现在交易额+已经提现了的金额   那么触发当前禁制
            return true;
        } else {
            return false;
        }
    }

//    /**
//     * 用户查询余额次数限制
//     * @param userId
//     * @param orderTypeId
//     * @param bankCard
//     * @return
//     */
//    public Map<String, Object> cashinfoqian4sendlogLimit(Long userId, Long orderTypeId, String bankCard){
//        try {
//            Map<String, Object> map = new HashMap<String, Object>();
//            Date date=new Date();
//            Calendar calendar = Calendar.getInstance();
//            calendar.setTime(date);
//            calendar.add(Calendar.MINUTE, -1);//系统当前时间减一分钟
//            date = calendar.getTime();
//            System.out.println("#######系统当前时间减一分钟########：" + date);
//            Qian4SendLog qian4SendLog = new Qian4SendLog();
//            qian4SendLog.setUserId(userId);
//            qian4SendLog.setOrderTypeId(orderTypeId);//交易类型
//            qian4SendLog.setAccountNumber(bankCard);//银行卡号
//            qian4SendLog.setStartDate(date);
//            qian4SendLog.setEndDate(new Date());
//            //查询一分钟成功查询余额次数
//            int count = qian4SendLogService.getEntityCountss(qian4SendLog);
//            System.out.println("#########一分钟成功查询余额次数#####:" + count);
//            //判断是否超限
//            if (count > 5 || count == 5) {
//                map.put("flag", false);
//                map.put("code", "fk0007");
//                map.put("value", 5);
//                map.put("description", "查询余额次数超限，一分钟最大次数为5次!");
//                return map;
//            }
//            Date date1=new Date();
//            Calendar calendar1 = Calendar.getInstance();
//            calendar1.setTime(date1);
//            calendar1.add(Calendar.DAY_OF_MONTH, -1);//系统当前时间减一天
//            date1 = calendar1.getTime();
//            System.out.println("#######系统当前时间减一天########："+date1);
//            qian4SendLog.setStartDate(date1);
//            qian4SendLog.setEndDate(new Date());
//            qian4SendLog.setAccountNumber(null);//银行卡号
//            //查询一天类内成功查询余额次数
//            int cardCount = qian4SendLogService.getEntityCounts(qian4SendLog);
//            System.out.println("#########一天成功查询余额次数#####:" + cardCount);
//            //判断是否超限
//            if (cardCount > 10 || cardCount == 10) {
//                map.put("flag", false);
//                map.put("code", "fk0008");
//                map.put("value", 10);
//                map.put("description", "查询余额次数超限，单日支持最大次数为10次!");
//                return map;
//            }
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
//    }

    /**
     * 用户查询余额次数限制
     * @param userId
     * @param orderTypeId
     * @param bankCard
     * @return
     */
    public Map<String, Object> userBalanceEnquiryLimit(Long userId, Long orderTypeId, String bankCard){
        try {

            Map<String, Object> userLimitMap = new HashMap<String, Object>();
            userLimitMap = getUserLeastLimit(userId, "RECEIVABLES");
            Long balanceEnquiryCnt = (Long) userLimitMap.get("dayMaxQueryCnt");
            if(balanceEnquiryCnt == null || balanceEnquiryCnt.intValue() == 0){
                return null;
            }
            Map<String, Object> map = new HashMap<String, Object>();
            Qian4SendLog qian4SendLog = new Qian4SendLog();
            qian4SendLog.setUserId(userId);
            qian4SendLog.setOrderTypeId(orderTypeId);//交易类型

            Calendar calendar = Calendar.getInstance();
            int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
            if(hourOfDay < 23){
                calendar.add(Calendar.DAY_OF_MONTH, -1);
            }
            calendar.set(Calendar.HOUR_OF_DAY,23);
            calendar.set(Calendar.MINUTE,0);
            calendar.set(Calendar.SECOND,0);
            qian4SendLog.setStartDate(calendar.getTime());
            qian4SendLog.setEndDate(new Date());
            //查询一天类内成功查询余额次数
            int cardCount = qian4SendLogService.getEntityCounts(qian4SendLog);
            System.out.println("#########一天成功查询余额次数#####:" + cardCount);
            //判断是否超限

            if (cardCount >= balanceEnquiryCnt.intValue()) {
                map.put("flag", false);
                map.put("code", "fk0008");
                map.put("value", balanceEnquiryCnt);
                map.put("description", "查询余额次数超限，单日支持最大次数为"+balanceEnquiryCnt+"次!");
                return map;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 秒到业务 单日单用户限额
     * @param userId
     * @param roleId
     * @param money
     * @param orderTypeId
     * @param ssTranslimit
     * @return
     */
    public Map<String, Object> ssTransLimit(Long userId, Long roleId, double money, Long orderTypeId, double ssTranslimit) throws Exception {
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            Date date = new Date();
            String day = DateConvertUtil.dateString(date);
            String yesterday = DateConvertUtil.dateString(DateConvertUtil.getSpecifiedDayBefore(date));


            TransOrder transOrder = new TransOrder();
            transOrder.setUserId(userId);
            transOrder.setRoleId(roleId);
            transOrder.setStartDate(DateConvertUtil.stringDateTime(yesterday + " 23:00:00"));
            transOrder.setEndDate(DateConvertUtil.stringDateTime(day + " 23:00:00"));
            transOrder.setOrderTypeId(orderTypeId);//交易类型
            if (orderTypeId == 8L) {//如果是提现
                transOrder.setOtherParam(" (O.STATUS = 1 OR O.STATUS = 2) ");
            } else {
                transOrder.setStatus(1);//交易成功状态
            }
            //查询今日成功交易总金额
            double totalMoney = transOrderDao.getTransMoneySum(transOrder);//查询 用户 当天提现 成功和正在处理中的 提现总金额
            double tempTotalMoney = money + totalMoney;


            //判断金额是否合格
            if (ssTranslimit != 0 && tempTotalMoney > ssTranslimit) {
                map.put("flag", false);
                map.put("code", "fk0003");
                map.put("value", ssTranslimit);
                map.put("description", "支付失败-金额超限，单日单用户支持最大金额为$param元!");
                return map;
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}